package com.cxf.windex.enums;

import java.math.BigDecimal;
import java.util.Random;

interface Cumputer{

  /**
   * 计算奖励
   * @param money  使用金额
   * @param tjMoney  统计金额
   * @param bonus   奖励
   * @return
   */
  public BigDecimal cumputer(BigDecimal money,BigDecimal tjMoney,BigDecimal bonus);
}

public enum BonusTypeEnum implements Cumputer{
  /**
   * 固定红包
   */
  FIXED("0", "固定红包"){
    public BigDecimal cumputer(BigDecimal money,BigDecimal tjMoney,BigDecimal bonus){return money.divide(tjMoney,0, BigDecimal.ROUND_DOWN).multiply(bonus);}
  },
  /**
   * 比例红包
   */
  RATE("1", "比例红包"){
    public BigDecimal cumputer(BigDecimal money,BigDecimal tjMoney,BigDecimal bonus){return money.multiply(bonus).divide(BigDecimal.valueOf(100));}
  },
  /**
   * 随机红包
   */
  RANDOM("2", "随机红包"){
    public  BigDecimal cumputer(BigDecimal money,BigDecimal tjMoney,BigDecimal bonus){
      BigDecimal newBonus= BigDecimal.valueOf(new Random().nextInt(bonus.intValue()));
      if(newBonus.intValue()==0){
        return BigDecimal.ONE;
      }
      return newBonus;}
  };

  private final String key;
  private final String desc;

  private BonusTypeEnum(String key, String desc) {
    this.key = key;
    this.desc = desc;
  }

  public static BonusTypeEnum keyOf(String key) {
    switch (key) {
      case "0":
        return BonusTypeEnum.FIXED;
      case "1":
        return BonusTypeEnum.RATE;
      case "2":
        return BonusTypeEnum.RANDOM;
      default:
        return null;
    }
  }

  public String getKey() {
    return this.key;
  }

  public String getDesc() {
    return this.desc;
  }
}
